import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:sweetim/controller/home_controller.dart';
import 'package:sweetim/view/friend_list_view.dart';

import 'chat_list_view.dart';

class HomeView extends StatelessWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    HomeController homeController = Get.put(HomeController());
    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: AppBar(
        title: const Text(
          "Sweet IM",
          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
        ),
      ),
      body: SafeArea(
        top: true,
        bottom: false,
        child: Obx(() {
          switch (homeController.selectIndex.value) {
            case 0:
              return const ChatList();
            case 1:
              return const FriendsList();
            case 2:
              return Center(
                  child: ElevatedButton(
                child: Text("退出登录"),
                onPressed: () async {
                  await homeController.cleanMember();
                  Get.offAndToNamed("/login");
                },
              ));
          }
          return Container();
        }),
      ),
      bottomNavigationBar: Obx(
        () => BottomNavigationBar(
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: FaIcon(FontAwesomeIcons.comment),
              label: '消息',
            ),
            BottomNavigationBarItem(
              icon: FaIcon(FontAwesomeIcons.userFriends),
              label: '朋友',
            ),
            BottomNavigationBarItem(
              icon: FaIcon(FontAwesomeIcons.userAlt),
              label: '我',
            ),
          ],
          currentIndex: homeController.selectIndex.value,
          onTap: homeController.bottomOnTap,
        ),
      ),
    );
  }
}
